package com.tanger.pay.wechat;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import java.io.IOException;
import java.util.Properties;

/**
 * @Description 微信配置
 * @Author Hchenbin
 * @Date 2024-01-04 17:06
 * @Version 1.0
 */
public class WeChatPayConfig {
    // APPID
    public static String appId;
    // 小程序密钥
    public static String secret;
    //商户ID
    public static String mchId;
    // 商户密钥/API密钥
    public static String key;
    //证书地址
    public static String certPath;
    // 回调地址
    public static String notifyUrl;
    // 小程序APPID
    public static String xcxAppId;

    // 统一下单API
    public static String unifiedorderUrl = "https://api.mch.weixin.qq.com/pay/unifiedorder";
    // 退款API
    public static String refundUrl = "https://api.mch.weixin.qq.com/secapi/pay/refund";
    // 转账(提现)API
    public static String transfers = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers";

    static {
        Resource resource = new ClassPathResource("WeChatConfig.properties");
        if (resource.exists()) {
            Properties properties = new Properties();
            try {
                properties.load(resource.getInputStream());
                appId = properties.getProperty("appId");
                secret = properties.getProperty("secret");
                mchId = properties.getProperty("mchId");
                key = properties.getProperty("key");
                certPath = properties.getProperty("certPath");
                notifyUrl = properties.getProperty("notifyUrl");

                xcxAppId = properties.getProperty("xcxAppId");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
